/**
 * Created by user on 2015/11/11.
 */

var userScoreService = require('../../../services/mis/appuser/userScoreService');
var messageUtil = require('../../../common/utils/messageUtil');
var toolUtil = require('../../../common/utils/toolUtil');
var mysqlUtil = require('../../../common/utils/mysqlUtil');

//用户积分列表
exports.userScoreList = function(req, res) {

    userScoreService.userScoreListService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when userScoreList...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when userScoreList...'));
        }else {
            var data = {
                count:results[0]["count"],
                totalPage: results[0]["totalPage"],
                list: results[1]
            };
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });
};


//添加情值
exports.addScoreManual = function (req, res) {
    var input = req.body;
    logger.debug('input:');
    logger.debug(input);

    input.__type__ = 'com.neighborhoods.service.score.dto.ScoreAddRequestDto';

    scoreProxy.invoke('addScoreManual', [input], function (err, result) {
        if (err) {
            logger.error('Exception happened when addScoreManual ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            var data = JSON.parse(decodeURIComponent(result));

            //toolUtil.putMessageGetuiPushMQ()

            logger.info(data);
            res.json(messageUtil.composeSucceededMessage(req, null, null));
        }
    });
};


//用户积分列表
exports.userScoreDetail = function(req, res) {

    userScoreService.userScoreDetailService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when userScoreDetail...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when userScoreDetail...'));
        }else {
            var data = {
                count:results[0]["count"],
                totalPage: results[0]["totalPage"],
                list: results[1]
            };
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });
};

